<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function createFuns() {
            var data = [], max = 3;
            window.onload = function () {
                for (var i = 0; i < data.length; i++) {
                    data[i]();
                }
            }
            return {
                addEvente: function () {
                    for (var i = 0; i < arguments.length; i++) {
                        if (data.length >= max) {
                            data.shift();
                        }
                        data.push(arguments[i]);
                    }
                },
                getData: function () {
                    return data;
                },
                removeEvente: function (funName) {
                    var index = data.indexOf(funName);
                    if (index != -1) {
                        data.splice(index, 1)
                    }
                }
            }
        }
        var objFn = createFuns();
        objFn.addEvente(function fn1() {
            console.log('这是fn1函数体');

        })
        var fn2 = function fn2() {
            console.log('这是fn2函数体');

        }
        objFn.addEvente(fn2);
        objFn.addEvente(function fn3() {
            console.log('这是fn3函数体');

        })
        console.log(objFn.getData());
        objFn.removeEvente(fn2);
        console.log(objFn.getData());
        objFn.addEvente(function fn4() {
            console.log('这是fn4函数体');

        },
            function fn5() {
                console.log('这是fn5函数体');

            })
        console.log(objFn.getData());


    </script>
</body>

</html>